/**
 * 
 */
package com.estock.platform.http.response;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.estock.common.model.security.Stock;
import com.estock.common.model.security.enums.StockStatus;
import com.estock.common.model.security.enums.StockType;

/**
 * @author richard
 *
 */
public class SinaStockBulkResponse extends SinaBaseResponse {
	
	List<Stock> stocks = new ArrayList<Stock>();
	public List<Stock> getStocks() {
		return stocks;
	}

	@Override
	protected void parse(String sinaJsString) {
		if (StringUtils.isEmpty(sinaJsString)) {
			throw new RuntimeException();
		}
		String[] tempArr = sinaJsString.split("=");
		String[] values = tempArr[1].replace("\"", "").split(",");
		
		Stock stock = new Stock();
		stock.setCode(tempArr[0].substring(tempArr[0].length() - 6, tempArr[0].length()));
		stock.setName(values[0]);
		stock.setType(Integer.valueOf(StockType.getStockTypeByAbbr(tempArr[0].substring(tempArr[0].length() - 8, tempArr[0].length() - 6))));
		stock.setStatus(Integer.valueOf(StringUtils.equals(values[1], "0.00") ? StockStatus.INACTIVE.getStatus() : StockStatus.ACTIVE.getStatus()));
		stock.setYesterPrice(Float.valueOf(values[2]));
		stock.setLatestPrice(Float.valueOf(values[3]));
		
		stocks.add(stock);
	}

}
